﻿using System.Linq;
using System.Net.Http.Formatting;
using System.Net.Http.Headers;
using System.Web.Http;
using Newtonsoft.Json.Serialization;

namespace MessageBoard
{
    public static class WebApiConfig
  {
    public static void Register(HttpConfiguration config)
    {
        config.Formatters.JsonFormatter.SupportedMediaTypes
            .Add(new MediaTypeHeaderValue("text/html"));


            var jsonFormatter = config.Formatters.OfType<JsonMediaTypeFormatter>().First();

        jsonFormatter.SerializerSettings.ContractResolver = 
                new CamelCasePropertyNamesContractResolver();

       config.Routes.MapHttpRoute(
            name: "RepliesRoute",
            routeTemplate: "api/topics/{topicid}/replies/{id}",
            defaults: new { controller = "replies", id = RouteParameter.Optional }
        );

      config.Routes.MapHttpRoute(
          name: "DefaultApi",
          routeTemplate: "api/topics/{id}",
          defaults: new { controller="topics", id = RouteParameter.Optional }
      );

      // Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type.
      // To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries.
      // For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712.
      //config.EnableQuerySupport();
    }
  }
}